package com.yycx.base.provider.handler;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.admin.client.entity.BaseRole;
import com.yycx.module.admin.provider.service.BaseRoleService;
import com.yycx.module.system.client.entity.SysDept;
import com.yycx.module.system.provider.service.SysDeptService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zyf
 */
@Component
@AllArgsConstructor
public class AdminUserGetHandler implements GetInterceptor {


    private final SysDeptService deptService;
    private final BaseRoleService roleService;

    @Override
    public void prepare(CriteriaQuery cq, EntityMap params) {

    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long deptId = map.getLong("deptId");
        Long companyId = map.getLong("companyId");
        if (FlymeUtils.isNotEmpty(deptId)) {
            SysDept dept = deptService.getById(deptId);
            map.put("deptName", dept.getDeptName());
        }
        if (FlymeUtils.isNotEmpty(companyId)) {
            List<BaseRole> roleList = roleService.findByCompanyId(companyId);
            map.put("roleList", roleList);
        }
    }
}
